<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Blog/classes/PhpFox_ComponentMemberBlogs.class.php, $Author:  $ */



/** Component for showing all member blogs
 *
 * @version $Id: PhpFox_ComponentMemberBlogs.class.php 297 2008-02-07 15:05:58Z phpfoxsv $
 * @package module.blog
 */
class PhpFox_Mod_Blog_ComponentMemberBlogs extends BaseComponent
{
    function process()
    {
        $oBlogItem = $this->_oModule->getItem('Blog');
        /* @var $oBlogItem PhpFox_Mod_Blog_ItemBlog */
        $oSecurityService = App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oBlogService = &$this->_oModule->getService('Blog');
        /* @var $oBlogService PhpFox_Mod_Blog_ServiceBlog */
        $oReq = &App::getRequest();
        $oUrl = &App::getUrl();
        $oTpl = &$this->_oModule->getTemplate();
        App::loadClass('Pager');

        $oSecurityService->checkPerm('blog', array('read_only', 'full'));
        $oSecurityService->checkAccess('blogs');
        $sUser = $oSecurityService->getCurrentUserLogin();
        if ($iId = $oReq->getInt('delete'))
        {
            $oSecurityService->checkPerm('blog', array('full'));
            $oBlogService->deleteBlog($iId);
            $oUrl->clearParams('delete');
            App::forward($oUrl->getUrl(), App::format('Mod_Blog.blog_deleted'), 'message', App::getPageName(), 'MemberBlogs');
        }
        $iPage = $oReq->getInt('page', 1);
        $iPageSize = App::getParam('public.pagesize');
        $aCond = array();
		$aCond['user_id'] = '= "'. App::getUser('id') .'"';
		$sSort = 'time DESC';

        list($aItems, $iCnt) = $oBlogItem->getList($aCond, $iPage, $iPageSize, $sSort);
        $oPager = &new Pager($iCnt, $iPage, $iPageSize);
        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);

        $oTpl->assignSrc('aItems', $aItems);
        $oTpl->assign(array(
        	'iFrom'            => ($iCnt) ? ($iFrom + 1) : 0,
        	'iTo'              => $iTo,
        	'iCnt'             => $iCnt,
        	'aPaging'          => ($iCnt) ? $oPager->getInfo($oUrl) : '',
        ));
        return $oTpl->fetch('MemberBlogs.html');
    }
}
?>